home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / VBXCTL.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  17KB  |  692 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1993, 1997 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   10.15  $
  6. //
  7. // Definition of TVbxControl and associated classes
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_VBXCTL_H)
  10. #define OWL_VBXCTL_H
  11. #define __OWL_VBXCTL_H   // Old-style define for VbxGen compatibility
  12.  
  13. #if !defined(OWL_CONTROL_H)
  14. # include <owl/control.h>
  15. #endif
  16. #if !defined(__BIVBX_H)
  17. # if defined(BI_PLAT_WIN32) && defined(_INC_DDEMLH)
  18. #   define _HSZ_DEFINED
  19. # endif
  20. # if defined(INC_OLE2)
  21. #   define NO_VBX_LPPICTURE   // VBX makes LPPICTURE FAR* PICTURE; OLE makes it FAR* IPICTURE 
  22. # endif
  23. # include <bivbx.h>
  24. #endif
  25. #if !defined(BI_PLAT_MSW)
  26. # error VBX supported only under MS Windows
  27. #endif
  28.  
  29. #if defined(BI_NAMESPACE)
  30. namespace OWL {
  31. #endif
  32.  
  33. class _OWLCLASS_RTL TXVbxLibrary;
  34.  
  35. // Generic definitions/compiler options (eg. alignment) preceeding the
  36. // definition of classes
  37. #include <services/preclass.h>
  38.  
  39. //
  40. // class TBIVbxLibrary
  41. // ~~~~~ ~~~~~~~~~~~~~
  42. class _USERCLASS TBIVbxLibrary {
  43.   public:
  44.     TBIVbxLibrary();
  45.    ~TBIVbxLibrary();
  46.  
  47. #if defined(OWL2_COMPAT)
  48.     typedef ::TXVbxLibrary TXVbxLibrary;  // Exceptions moved to global scope
  49. #endif
  50. };
  51.  
  52. //
  53. // class TXVbxLibrary
  54. // ~~~~~ ~~~~~~~~~~~~
  55. class _OWLCLASS_RTL TXVbxLibrary : public TXOwl {
  56.   public:
  57.     TXVbxLibrary();
  58.  
  59. #if defined(BI_NO_COVAR_RET)
  60.     TXBase* Clone();
  61. #else
  62.     TXVbxLibrary* Clone();
  63. #endif
  64.     void Throw();
  65.  
  66.     static void Raise();
  67. };
  68.  
  69. class _USERCLASS TVbxControl;
  70.  
  71. //
  72. // class TVbxEventHandler
  73. // ~~~~~ ~~~~~~~~~~~~~~~~
  74. class _USERCLASS TVbxEventHandler : virtual public TEventHandler {
  75.   protected:
  76.     TResult  EvVbxDispatch(TParam1 p1, TParam2 p2);
  77.     TResult  EvVbxInitForm(TParam1 p1, TParam2 p2);
  78.  
  79. #if defined(BI_PLAT_WIN32)
  80.  
  81.   public:
  82.     TWindow *GetWindowPtr( HWND Window );
  83.  
  84.   private:
  85.     static HWND HWND16TO32(HWND hw) {
  86.      return ((HWND)(((DWORD)((WORD)(hw)))|0xffff0000));
  87.     }
  88.  
  89.     typedef struct {
  90.       HWND         hWnd;
  91.       TVbxControl *vbx;
  92.     } PARAM, FAR *LPPARAM;
  93.  
  94.     typedef void (*LPFNFOREACH)(TWindow*, void*);
  95.  
  96.     static void FindVBX(TWindow *c, LPPARAM p);
  97. #endif BI_PLAT_WIN32
  98.  
  99.   DECLARE_RESPONSE_TABLE(TVbxEventHandler);
  100. };
  101.  
  102. //
  103. // class TVbxControl
  104. // ~~~~~ ~~~~~~~~~~~
  105. class _USERCLASS TVbxControl : public TControl, public TVbxEventHandler {
  106.   public:
  107.     TVbxControl(TWindow*        parent,
  108.                 int             id,
  109.                 const char far* vbxName,
  110.                 const char far* vbxClass,
  111.                 const char far* title,
  112.                 int             x,
  113.                 int             y,
  114.                 int             w,
  115.                 int             h,
  116.                 long            initLen = 0,
  117.                 void far*       initData = 0,
  118.                 TModule*        module = 0);
  119.  
  120.     TVbxControl(TWindow* parent, int resourceId, TModule* module = 0);
  121.    ~TVbxControl();
  122.  
  123.     void SetupWindow();
  124.  
  125.     // Properties
  126.     //
  127.     int GetNumProps();
  128.     int GetPropIndex(const char far* name);
  129. #if defined(BI_PLAT_WIN16)
  130.     const char far* GetPropName(int propIndex);
  131. #endif
  132.     void GetPropName(int propIndex, string& str);
  133.     int GetPropType(int propIndex);
  134.     int GetPropType(char far* name);
  135.     bool IsArrayProp(int propIndex);
  136.     bool IsArrayProp(char far* name);
  137.  
  138.     // Get properties by index
  139.     //
  140.     bool GetProp(int propIndex, int& value, int arrayIndex=-1);
  141.     bool GetProp(int propIndex, long& value, int arrayIndex=-1);
  142. #if defined(BI_UNIQUE_BOOL)
  143.     bool GetProp(int propIndex, bool& value, int arrayIndex=-1);
  144. #endif
  145.     bool GetProp(int propIndex, ENUM& value, int arrayIndex=-1);
  146.     bool GetProp(int propIndex, HPIC& value, int arrayIndex=-1);
  147.     bool GetProp(int propIndex, float& value, int arrayIndex=-1);
  148.     bool GetProp(int propIndex, string& value, int arrayIndex=-1);
  149.     bool GetProp(int propIndex, COLORREF& value, int arrayIndex=-1);
  150.  
  151.     // Get properties by name
  152.     //
  153.     bool GetProp(const char far* name, int& value, int arrayIndex=-1);
  154.     bool GetProp(const char far* name, long& value, int arrayIndex=-1);
  155. #if defined(BI_UNIQUE_BOOL)
  156.     bool GetProp(const char far* name, bool& value, int arrayIndex=-1);
  157. #endif
  158.     bool GetProp(const char far* name, ENUM& value, int arrayIndex=-1);
  159.     bool GetProp(const char far* name, HPIC& value, int arrayIndex=-1);
  160.     bool GetProp(const char far* name, float& value, int arrayIndex=-1);
  161.     bool GetProp(const char far* name, string& value, int arrayIndex=-1);
  162.     bool GetProp(const char far* name, COLORREF& value, int arrayIndex=-1);
  163.  
  164.     // Set properties by index
  165.     //
  166.     bool SetProp(int propIndex, int value, int arrayIndex=-1);
  167.     bool SetProp(int propIndex, long value, int arrayIndex=-1);
  168.     bool SetProp(int propIndex, ENUM value, int arrayIndex=-1);
  169.     bool SetProp(int propIndex, HPIC value, int arrayIndex=-1);
  170.     bool SetProp(int propIndex, float value, int arrayIndex=-1);
  171.     bool SetProp(int propIndex, const string& value, int arrayIndex=-1);
  172.     bool SetProp(int propIndex, const char far* value, int arrayIndex=-1);
  173.     bool SetProp(int propIndex, COLORREF value, int arrayIndex=-1);
  174.  
  175.     // Set properties by name
  176.     //
  177.     bool SetProp(const char far* name, int value, int arrayIndex=-1);
  178.     bool SetProp(const char far* name, long value, int arrayIndex=-1);
  179.     bool SetProp(const char far* name, ENUM value, int arrayIndex=-1);
  180.     bool SetProp(const char far* name, HPIC value, int arrayIndex=-1);
  181.     bool SetProp(const char far* name, float value, int arrayIndex=-1);
  182.     bool SetProp(const char far* name, const string& value, int arrayIndex=-1);
  183.     bool SetProp(const char far* name, const char far* value, int arrayIndex=-1);
  184.     bool SetProp(const char far*, COLORREF value, int arrayIndex=-1);
  185.  
  186.     // Events
  187.     //
  188.     int GetNumEvents();
  189.     int GetEventIndex(const char far* name);
  190. #if defined(BI_PLAT_WIN16)
  191.     const char far* GetEventName(int eventIndex);
  192. #endif
  193.     void GetEventName(int eventIndex, string& str);
  194.  
  195.     // Methods
  196.     //
  197.     bool AddItem(int index, const char far* item);
  198.     bool Drag(int action);
  199.     bool Move(long x, long y, long w, long h);
  200.     bool Refresh();
  201.     bool RemoveItem(int index);
  202.  
  203.     // Control
  204.     //
  205.     HCTL GetHCTL();
  206.  
  207.   protected:
  208.     char far* GetClassName();
  209.     void PerformCreate(int menuOrId);
  210.     bool GetVBXProperty(int propIndex, void far *value, int arrayIndex=-1);
  211.     bool SetVBXProperty(int propIndex, int32 value, int arrayIndex=-1);
  212.  
  213.   private:
  214.     HCTL      HCtl;
  215.     char far* VbxName;
  216.     char far* VbxClass;
  217.     long      InitLen;
  218.     void far* InitData;
  219.  
  220.     TResult EvDefaultProcessing(TParam1, TParam2);
  221.  
  222.   DECLARE_RESPONSE_TABLE(TVbxControl);
  223.   DECLARE_CASTABLE;
  224. };
  225.  
  226. // Generic definitions/compiler options (eg. alignment) following the
  227. // definition of classes
  228. #include <services/posclass.h>
  229.  
  230. //----------------------------------------------------------------------------
  231.  
  232. //
  233. // Response table macros for VBX events
  234. //
  235. #define EV_VBXEVENTNAME(id,name,method)\
  236.   {WM_VBXNAME,id,(TAnyDispatcher)name,(TMyPMF)VbxSig(&TMyClass::method)}
  237.  
  238. #define EV_VBXEVENTINDEX(id,event,method)\
  239.   {WM_VBXBASE+event,id,(TAnyDispatcher)::i_LPARAM_Dispatch,\
  240.   (TMyPMF)VbxSig(&TMyClass::method)}
  241.  
  242. //
  243. // WM_VBXFIREEVENT signature template
  244. //
  245. template <class T>
  246. inline void(T::*VbxSig(void(T::*pmf)(VBXEVENT FAR*))) (VBXEVENT FAR*)
  247. {
  248.   return pmf;
  249. }
  250.  
  251. //
  252. // VBXDispatch - dispatch function to crack a WM_VBXFIREEVENT message and
  253. // pass control to a pointer to member function.
  254. //
  255. TResult
  256. VBXDispatch(GENERIC& generic,
  257.             void    (GENERIC::*pmf)(VBXEVENT FAR*),
  258.             TParam1  param1,
  259.             TParam2  param2);
  260.  
  261. #if defined(BI_NAMESPACE)
  262. } // namespace OWL
  263. #endif
  264.  
  265. //----------------------------------------------------------------------------
  266. // TVbxControl Inlines
  267. //
  268.  
  269. //
  270. // Retrieve the number of properties in the VBX.
  271. //
  272. inline int TVbxControl::GetNumProps()
  273. {
  274.   return ::VBXGetNumProps(HCtl);
  275. }
  276.  
  277. //
  278. // Convert the name of the property into an index.
  279. //
  280. inline int TVbxControl::GetPropIndex(const char far* name)
  281. {
  282.   return ::VBXGetPropIndex(HCtl, name);
  283. }
  284.  
  285. #if defined(BI_PLAT_WIN16)
  286. //
  287. // Retrieve the name of the property at a particular index.
  288. // For portability between 16-bits and 32-bits use the other form of
  289. // GetPropName().
  290. //
  291. inline const char far* TVbxControl::GetPropName(int propIndex)
  292. {
  293.   return ::VBXGetPropName(HCtl, propIndex);
  294. }
  295. #endif
  296.  
  297. //
  298. // Retrieve the name of the property at a particular index.
  299. //
  300. inline void TVbxControl::GetPropName(int propIndex, string& str)
  301. {
  302.   char buff[64];
  303.   ::VBXGetPropNameBuf(HCtl, propIndex, buff, sizeof buff);
  304.   str = buff;
  305. }
  306.  
  307. //
  308. // Retrieve the type of the property.
  309. // See PTYPE_XXXX in BIVBX.H.
  310. //
  311. inline int TVbxControl::GetPropType(int propIndex)
  312. {
  313.   return ::VBXGetPropType(HCtl, propIndex);
  314. }
  315.  
  316. //
  317. // Retrieve the type of the property.
  318. // See PTYPE_XXXX in BIVBX.H.
  319. //
  320. inline int TVbxControl::GetPropType(char far* name)
  321. {
  322.   return GetPropType(GetPropIndex(name));
  323. }
  324.  
  325. //
  326. // Return true if the property is an array.
  327. //
  328. inline bool TVbxControl::IsArrayProp(int propIndex)
  329. {
  330.   return ::VBXIsArrayProp(HCtl, propIndex);
  331. }
  332.  
  333. //
  334. // Return true if the property is an array.
  335. //
  336. inline bool TVbxControl::IsArrayProp(char far* name)
  337. {
  338.   return IsArrayProp(GetPropIndex(name));
  339. }
  340.  
  341.  
  342. //----------------------------------------------------------------------------
  343. // Get properties by id
  344. //
  345.  
  346. //
  347. inline bool
  348. TVbxControl::GetProp(int propIndex, int& value, int arrayIndex)
  349. {
  350. #if defined(BI_PLAT_WIN32)
  351.   int16 temp;
  352.   if (GetVBXProperty(propIndex, &temp, arrayIndex)) {
  353.          value = temp;
  354.          return true;
  355.   }
  356.   return false;
  357. #else
  358.   return GetVBXProperty(propIndex, &value, arrayIndex);
  359. #endif
  360. }
  361.  
  362. //
  363. inline bool
  364. TVbxControl::GetProp(int propIndex, long& value, int arrayIndex)
  365. {
  366.   return GetVBXProperty(propIndex, &value, arrayIndex);
  367. }
  368.  
  369. #if defined(BI_UNIQUE_BOOL)
  370. //
  371. // Retrieve the boolean property at a particular index.
  372. //
  373. inline bool
  374. TVbxControl::GetProp(int propIndex, bool& value, int arrayIndex)
  375. {
  376. #if defined(BI_PLAT_WIN32)
  377.   int16 temp;
  378.   if (GetVBXProperty(propIndex, &temp, arrayIndex)) {
  379.     value = temp;
  380.     return true;
  381.   }
  382.   return false;
  383. #else
  384.   return GetVBXProperty(propIndex, &value, arrayIndex);
  385. #endif
  386. }
  387. #endif
  388.  
  389. //
  390. inline bool
  391. TVbxControl::GetProp(int propIndex, ENUM& value, int arrayIndex)
  392. {
  393.   int16 temp;
  394.   bool rv = GetVBXProperty(propIndex, &temp, arrayIndex);
  395.   value = (ENUM)temp;
  396.   return rv;
  397. }
  398.  
  399. //
  400. inline bool
  401. TVbxControl::GetProp(int propIndex, HPIC& value, int arrayIndex)
  402. {
  403.   return GetVBXProperty(propIndex, &value, arrayIndex);
  404. }
  405.  
  406. //
  407. inline bool
  408. TVbxControl::GetProp(int propIndex, float& value, int arrayIndex)
  409. {
  410.   return GetVBXProperty(propIndex, &value, arrayIndex);
  411. }
  412.  
  413. //
  414. inline bool
  415. TVbxControl::GetProp(int propIndex, COLORREF& value, int arrayIndex)
  416. {
  417.   return GetVBXProperty(propIndex, &value, arrayIndex);
  418. }
  419.  
  420. //----------------------------------------------------------------------------
  421. // Get properties by name
  422. //
  423.  
  424. #if defined(BI_UNIQUE_BOOL)
  425. //
  426. inline bool
  427. TVbxControl::GetProp(const char far* name, int& value, int arrayIndex)
  428. {
  429.   return GetProp(GetPropIndex(name), value, arrayIndex);
  430. }
  431. #endif
  432.  
  433. //
  434. inline bool
  435. TVbxControl::GetProp(const char far* name, long& value, int arrayIndex)
  436. {
  437.   return GetProp(GetPropIndex(name), value, arrayIndex);
  438. }
  439.  
  440. //
  441. // Retrieve the boolean property at a particular index.
  442. //
  443. inline bool
  444. TVbxControl::GetProp(const char far* name, bool& value, int arrayIndex)
  445. {
  446.   return GetProp(GetPropIndex(name), value, arrayIndex);
  447. }
  448.  
  449. //
  450. inline bool
  451. TVbxControl::GetProp(const char far* name, ENUM& value, int arrayIndex)
  452. {
  453.   return GetProp(GetPropIndex(name), value, arrayIndex);
  454. }
  455.  
  456. //
  457. inline bool
  458. TVbxControl::GetProp(const char far* name, HPIC& value, int arrayIndex)
  459. {
  460.   return GetProp(GetPropIndex(name), value, arrayIndex);
  461. }
  462.  
  463. //
  464. inline bool
  465. TVbxControl::GetProp(const char far* name, float& value, int arrayIndex)
  466. {
  467.   return GetProp(GetPropIndex(name), value, arrayIndex);
  468. }
  469.  
  470. //
  471. inline bool
  472. TVbxControl::GetProp(const char far* name, string& value, int arrayIndex)
  473. {
  474.   return GetProp(GetPropIndex(name), value, arrayIndex);
  475. }
  476.  
  477. //
  478. inline bool
  479. TVbxControl::GetProp(const char far* name, COLORREF& value, int arrayIndex)
  480. {
  481.   return GetProp(GetPropIndex(name), value, arrayIndex);
  482. }
  483.  
  484. //----------------------------------------------------------------------------
  485. // Set properties by id
  486. //
  487.  
  488. //
  489. inline bool
  490. TVbxControl::SetProp(int propIndex, int value, int arrayIndex)
  491. {
  492.   return SetVBXProperty(propIndex, value, arrayIndex);
  493. }
  494.  
  495. //
  496. inline bool
  497. TVbxControl::SetProp(int propIndex, long value, int arrayIndex)
  498. {
  499.   return SetVBXProperty(propIndex, value, arrayIndex);
  500. }
  501.  
  502. //
  503. inline bool
  504. TVbxControl::SetProp(int propIndex, HPIC value, int arrayIndex)
  505. {
  506.   return SetVBXProperty(propIndex, value, arrayIndex);
  507. }
  508.  
  509. //
  510. inline bool
  511. TVbxControl::SetProp(int propIndex, ENUM value, int arrayIndex)
  512. {
  513.   return SetVBXProperty(propIndex, (long)value, arrayIndex);
  514. }
  515.  
  516. //
  517. inline bool
  518. TVbxControl::SetProp(int propIndex, float value, int arrayIndex)
  519. {
  520.   return SetVBXProperty(propIndex, *((long*)&value), arrayIndex);
  521. }
  522.  
  523. //
  524. inline bool
  525. TVbxControl::SetProp(int propIndex, const string& value, int arrayIndex)
  526. {
  527.   return SetVBXProperty(propIndex, long(value.c_str()), arrayIndex);
  528. }
  529.  
  530. //
  531. inline bool
  532. TVbxControl::SetProp(int propIndex, const char far* value, int arrayIndex)
  533. {
  534.   return SetVBXProperty(propIndex, (long)value, arrayIndex);
  535. }
  536.  
  537. //
  538. inline bool
  539. TVbxControl::SetProp(int propIndex, COLORREF value, int arrayIndex)
  540. {
  541.   return SetVBXProperty(propIndex, (long)value, arrayIndex);
  542. }
  543.  
  544. //----------------------------------------------------------------------------
  545. // Set properties by name
  546. //
  547.  
  548. //
  549. inline bool
  550. TVbxControl::SetProp(const char far* name, int value, int arrayIndex)
  551. {
  552.   return SetProp(GetPropIndex(name), value);
  553. }
  554.  
  555. //
  556. inline bool
  557. TVbxControl::SetProp(const char far* name, long value, int arrayIndex)
  558. {
  559.   return SetProp(GetPropIndex(name), value);
  560. }
  561.  
  562. //
  563. inline bool
  564. TVbxControl::SetProp(const char far* name, ENUM value, int arrayIndex)
  565. {
  566.   return SetProp(GetPropIndex(name), value);
  567. }
  568.  
  569. //
  570. inline bool
  571. TVbxControl::SetProp(const char far* name, HPIC value, int arrayIndex)
  572. {
  573.   return SetProp(GetPropIndex(name), value);
  574. }
  575.  
  576. //
  577. inline bool
  578. TVbxControl::SetProp(const char far* name, float value, int arrayIndex)
  579. {
  580.   return SetProp(GetPropIndex(name), value);
  581. }
  582.  
  583. //
  584. inline bool
  585. TVbxControl::SetProp(const char far* name, const string& value, int arrayIndex)
  586. {
  587.   return SetProp(GetPropIndex(name), value.c_str());
  588. }
  589.  
  590. //
  591. inline bool
  592. TVbxControl::SetProp(const char far* name, const char far* value, int arrayIndex)
  593. {
  594.   return SetProp(GetPropIndex(name), value);
  595. }
  596.  
  597. //
  598. inline bool
  599. TVbxControl::SetProp(const char far* name, COLORREF value, int arrayIndex)
  600. {
  601.   return SetProp(GetPropIndex(name), value);
  602. }
  603.  
  604. //----------------------------------------------------------------------------
  605. //
  606.  
  607. //
  608. // Return the number of events.
  609. //
  610. inline int
  611. TVbxControl::GetNumEvents()
  612. {
  613.   return ::VBXGetNumEvents(HCtl);
  614. }
  615.  
  616. //
  617. // Return the index of the event given its name.
  618. //
  619. inline int
  620. TVbxControl::GetEventIndex(const char far* name)
  621. {
  622.   return ::VBXGetEventIndex(HCtl, name);
  623. }
  624.  
  625. #if defined(BI_PLAT_WIN16)
  626. //
  627. // Retrieve the name of the event at a particular index.
  628. // For portability between 16-bits and 32-bits use the other form of
  629. // GetEventName().
  630. //
  631. inline const char far*
  632. TVbxControl::GetEventName(int eventIndex)
  633. {
  634.   return ::VBXGetEventName(HCtl, eventIndex);
  635. }
  636. #endif
  637.  
  638. //
  639. // Retrieve the name of the event at a particular index.
  640. //
  641. inline void
  642. TVbxControl::GetEventName(int eventIndex, string& str)
  643. {
  644.   char buff[64];
  645.   ::VBXGetEventNameBuf(HCtl, eventIndex, buff, sizeof buff);
  646.   str = buff;
  647. }
  648.  
  649. //
  650. inline bool
  651. TVbxControl::AddItem(int index, const char far* item)
  652. {
  653.   return ::VBXMethodAddItem(HCtl, index, item);
  654. }
  655.  
  656. //
  657. inline bool
  658. TVbxControl::Drag(int action)
  659. {
  660.   return ::VBXMethodDrag(HCtl, action);
  661. }
  662.  
  663. //
  664. inline bool
  665. TVbxControl::Move(long x, long y, long w, long h)
  666. {
  667.   return ::VBXMethodMove(HCtl, x, y, w, h);
  668. }
  669.  
  670. //
  671. inline bool
  672. TVbxControl::Refresh()
  673. {
  674.   return ::VBXMethodRefresh(HCtl);
  675. }
  676.  
  677. //
  678. inline bool
  679. TVbxControl::RemoveItem(int index)
  680. {
  681.   return ::VBXMethodRemoveItem(HCtl, index);
  682. }
  683.  
  684. //
  685. inline HCTL
  686. TVbxControl::GetHCTL()
  687. {
  688.   return HCtl;
  689. }
  690.  
  691. #endif  // OWL_VBXCTL_H
  692.